<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- 角色列表 -->
<script type="text/javascript">
function addRole(){
    $.dialog({
        title: '添加角色',
        content: $("#addRoleDiv").html(),
        ok: function () {
            $("#roleForm").ajaxSubmit({
                url:'${ctx }/role/add',
                type:"POST",
                dataType:'json',
                success:function(data){
                    if(data.status=='success'){
                        showSuccess();
                        $.dialog.close();
                    }else{
                        showError();
                        $.dialog.close();
                    }
                    
                }           
            }); 
        },
        okVal:'提交',
        cancel: true,
        cancelVal:'取消',
        close:function(){
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
        }
    });
}

function toAssignPurview(roleId){
	$.dialog.open("${ctx}/rolePurview/assignPurview?roleId="+roleId,{
        title: '分配权限', 
        width: 300,
        height: 350,
        close:function(){
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
    }});
}

function deleteRole(roleId){
    $.post("${ctx}/role/delete",{ids:roleId},function(data){
        if(data.status=='success'){
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
            showSuccess();
        }else{
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
            showError();
        }
    },"json");
}

function deleteAllSelectedRole(){
    var roleId="";
    $.each($("input[name=roleId]:checked"),function(i,n){
    	roleId+=$(n).val()+",";
    });
    $.post("${ctx}/role/delete",{ids:roleId},function(data){
        if(data.status=='success'){
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
            showSuccess();
        }else{
            loadMainHtml("${ctx}/role/toList?time="+new Date().getTime());
            showError();
        }
    },"json");
}
</script>
<%@ include file="/common/jsp/taglibs.jsp" %>
        <div class="pad20"   style="font-size: 13px;line-height: 20px;" >
            <a href="javascript:void(0);" class="button" onclick="addRole();">
              <span class="ui-icon ui-icon-plusthick"></span>
                                      添加角色
          </a>
        </div>
        <div class="pad20">
          <table class="fullwidth"  cellspacing="0" border="0">
           <thead>
            <tr>
              <td><input type="checkbox" class="checkall" />全选</td>
              <td>名称</td>
              <td>描述</td>
              <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${rolesList }" var="role"  varStatus="i">
              <tr <c:if test="${i.index%2!=0 }">class="odd"</c:if>>
               <td><input type="checkbox" name="roleId" value="${role.roleId }"/></td>
               <td>${role.name }</td>
               <td>${role.description }</td>
               <td>
                 <span  onclick="toAssignPurview(${role.roleId });">分配权限</span>
                 <span onclick="deleteRole(${role.roleId });">删除</span>
               </td>
              </tr>
            </c:forEach>
            </tbody>           
          </table>
        </div>
        <div class="pad20">
        <div style="float:left">
           <a href="javascript:void(0);"  onclick="deleteAllSelectedRole();"  class="button tooltip" title="删除选中项"><span class="ui-icon ui-icon-trash"></span>删除选中</a>
        </div>
        </div>
        <!-- 添加角色 -->
        <div  id="addRoleDiv"  style="display:none;">
        <form  id="roleForm">
        <p>
           <label>名称:</label>
           <input type="text"  name="name"   class="sf"/>
        </p>
        <p>
           <label>描述:</label>
           <textarea name="description"  rows="5" cols="15"></textarea>
        </p>
        </form>
        </div>      
